package com.tensquare.sms.consumer;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.exceptions.ClientException;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import util.SmsUtil;

import java.util.Map;

/**
 * Created by Administrator on 2021/4/20.
 * 接受消息
 */

@Component
@RabbitListener(queues = "itcast-queue-sms")
public class SmsListner {

    @Autowired
    private SmsUtil smsUtil;
    @RabbitHandler
    public void sendSms(Map map){
        try {
            String mobile = (String) map.get("mobile");
            // String checkCode = (String) map.get("checkCode");
            String temppaltecode = (String) map.get("temppaltecode");
            Map<String,String>paramMap = (Map<String, String>) map.get("paramMap");
            String tempateParams = JSONObject.toJSONString(paramMap);
            System.out.println("接收到的消息为:"+mobile+tempateParams+temppaltecode);
            smsUtil.sendSms(mobile,temppaltecode,tempateParams);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
} 
